﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcps.Web.projectinfo
{
    public partial class Add : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["login"] != null)
                {
                    BindDDL();
                }
                else
                {
                    Maticsoft.Common.MessageBox.ResponseScript(this, "top.location.href='../Default.aspx'");
                }
                
            }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            #region 验证
            //if (this.txtbidid.Text.Trim().Length == 0)
            //{
            //    strErr += "bidid不能为空！\\n";
            //}
            //if (this.txtpurchaseid.Text.Trim().Length == 0)
            //{
            //    strErr += "purchaseid不能为空！\\n";
            //}
            //if (this.txtusework.Text.Trim().Length == 0)
            //{
            //    strErr += "usework不能为空！\\n";
            //}
            //if (this.txtprojectname.Text.Trim().Length == 0)
            //{
            //    strErr += "projectname不能为空！\\n";
            //}
            //if (this.txtprojecttype.Text.Trim().Length == 0)
            //{
            //    strErr += "projecttype不能为空！\\n";
            //}
            //if (this.txtsupplier.Text.Trim().Length == 0)
            //{
            //    strErr += "supplier不能为空！\\n";
            //}
            //if (this.txtmateriel.Text.Trim().Length == 0)
            //{
            //    strErr += "materiel不能为空！\\n";
            //}
            //if (this.txtunit.Text.Trim().Length == 0)
            //{
            //    strErr += "unit不能为空！\\n";
            //}
            //if (!PageValidate.IsNumber(txtnums.Text))
            //{
            //    strErr += "数量格式错误！请填写数字\\n";
            //}
            if (!PageValidate.IsDateTime(txtdeliverydate.Text))
            {
                strErr += "合同交货时间格式错误！请填写时间\\n";
            }
            if (!PageValidate.IsDateTime(txtarrivaldate.Text))
            {
                strErr += "项目单位要求到货时间格式错误！请填写时间\\n";
            }
            if (!PageValidate.IsDateTime(txtworkdate.Text))
            {
                strErr += "项目计划投运时间格式错误！请填写时间\\n";
            }
            if (!PageValidate.IsDateTime(txtdrawingplandate.Text))
            {
                strErr += "图纸应提交设计单位时间格式错误！请填写时间\\n";
            }
            //if (this.txtdrawingstate.Text.Trim().Length == 0)
            //{
            //    strErr += "drawingstate不能为空！\\n";
            //}
            if (!PageValidate.IsDateTime(txtdrawingsubmitdate.Text))
            {
                strErr += "图纸应提交设计单位时间格式错误！请填写时间\\n";
            }
            if (!PageValidate.IsDateTime(txtdrawingconfirmdate.Text))
            {
                strErr += "要求设计单位确认时间格式错误！请填写时间\\n";
            }
            //if (this.txtdesignstate.Text.Trim().Length == 0)
            //{
            //    strErr += "designstate不能为空！\\n";
            //}
            //if (this.txtmajormaterielpurchase.Text.Trim().Length == 0)
            //{
            //    strErr += "majormaterielpurchase不能为空！\\n";
            //}
            //if (this.txtdeviceproductionstate.Text.Trim().Length == 0)
            //{
            //    strErr += "deviceproductionstate不能为空！\\n";
            //}
            //if (this.txtmothstate.Text.Trim().Length == 0)
            //{
            //    strErr += "mothstate不能为空！\\n";
            //}
            //if (this.txtnextmoth.Text.Trim().Length == 0)
            //{
            //    strErr += "nextmoth不能为空！\\n";
            //}
            if (!PageValidate.IsDateTime(txtplanarrivedate.Text))
            {
                strErr += "计划到货时间格式错误！\\n";
            }
            //if (this.txtcoordinate.Text.Trim().Length == 0)
            //{
            //    strErr += "coordinate不能为空！\\n";
            //}
            //if (this.txtremark.Text.Trim().Length == 0)
            //{
            //    strErr += "remark不能为空！\\n";
            //}
            //if (this.txtproid.Text.Trim().Length == 0)
            //{
            //    strErr += "proid不能为空！\\n";
            //}
            if (!PageValidate.IsDateTime(txtrealdate.Text))
            {
                strErr += "实际到货时间格式错误！\\n";
            }
            //if (this.txtreceivedname.Text.Trim().Length == 0)
            //{
            //    strErr += "receivedname不能为空！\\n";
            //}
            //if (this.txtsuppliername.Text.Trim().Length == 0)
            //{
            //    strErr += "suppliername不能为空！\\n";
            //}
            //if (this.txtsupplierphone.Text.Trim().Length == 0)
            //{
            //    strErr += "supplierphone不能为空！\\n";
            //}
            //if (this.txtcheckstate.Text.Trim().Length == 0)
            //{
            //    strErr += "checkstate不能为空！\\n";
            //}
            //if (!PageValidate.IsDateTime(txttransactdate.Text))
            //{
            //    strErr += "办理日期格式错误！\\n";
            //}
            //if (this.txtagent.Text.Trim().Length == 0)
            //{
            //    strErr += "agent不能为空！\\n";
            //}
            //if (!PageValidate.IsNumber(txttableid.Text))
            //{
            //    strErr += "tableid格式错误！\\n";
            //}
            #endregion

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string bidid = this.txtbidid.Text;
            string purchaseid = this.txtpurchaseid.Text;
            string usework = this.txtusework.Text;
            string projectname = this.txtprojectname.Text;
            string projecttype = this.txtprojecttype.Text;
            string supplier = this.txtsupplier.Text;
            string materiel = this.txtmateriel.Text;
            string unit = this.txtunit.Text;
            float nums = float.Parse(this.txtnums.Text);
            DateTime contractdate = DateTime.Parse(this.txtcontractdate.Text);
            DateTime deliverydate = DateTime.Parse(this.txtdeliverydate.Text);
            DateTime arrivaldate = DateTime.Parse(this.txtarrivaldate.Text);
            DateTime workdate = DateTime.Parse(this.txtworkdate.Text);
            DateTime drawingplandate = DateTime.Parse(this.txtdrawingplandate.Text);
            string drawingstate = this.txtdrawingstate.Text;
            DateTime drawingsubmitdate = DateTime.Parse(this.txtdrawingsubmitdate.Text);
            DateTime drawingconfirmdate = DateTime.Parse(this.txtdrawingconfirmdate.Text);
            string designstate = this.txtdesignstate.Text;
            string majormaterielpurchase = this.txtmajormaterielpurchase.Text;
            string deviceproductionstate = this.txtdeviceproductionstate.Text;
            string mothstate = this.txtmothstate.Text;
            string nextmoth = this.txtnextmoth.Text;
            string planarrivedate =this.txtplanarrivedate.Text;
            string coordinate = this.txtcoordinate.Text;
            string remark = this.txtremark.Text;
            string proid = this.txtproid.Text;
            DateTime realdate = DateTime.Parse(this.txtrealdate.Text);
            string receivedname = this.txtreceivedname.Text;
            string receivedphone = this.txtreceivedphone.Text;
            string suppliername = this.txtsuppliername.Text;
            string supplierphone = this.txtsupplierphone.Text;
            //string checkstate = this.txtcheckstate.Text;
            //DateTime transactdate = DateTime.Parse(this.txttransactdate.Text);
            //string agent = this.txtagent.Text;
            //int tableid = int.Parse(this.txttableid.Text);

            int tableid = int.Parse(this.ddltables.SelectedItem.Value);

            lcps.Model.projectinfo model = new lcps.Model.projectinfo();
            model.bidid = bidid;
            model.purchaseid = purchaseid;
            model.usework = usework;
            model.projectname = projectname;
            model.projecttype = projecttype;
            model.supplier = supplier;
            model.materiel = materiel;
            model.unit = unit;
            model.nums = nums;
            model.contractdate = contractdate;
            model.deliverydate = deliverydate;
            model.arrivaldate = arrivaldate;
            model.workdate = workdate;
            model.drawingplandate = drawingplandate;
            model.drawingstate = drawingstate;
            model.drawingsubmitdate = drawingsubmitdate;
            model.drawingconfirmdate = drawingconfirmdate;
            model.designstate = designstate;
            model.majormaterielpurchase = majormaterielpurchase;
            model.deviceproductionstate = deviceproductionstate;
            model.mothstate = mothstate;
            model.nextmoth = nextmoth;
            model.planarrivedate = planarrivedate;
            model.coordinate = coordinate;
            model.remark = remark;
            model.proid = proid;
            model.realdate = realdate;
            model.receivedname = receivedname;
            model.receivedphone = receivedphone;
            model.suppliername = suppliername;
            model.supplierphone = supplierphone;
            //model.checkstate = checkstate;
            //model.transactdate = transactdate;
            //model.agent = agent;
            model.tableid = tableid;

            lcps.BLL.projectinfo bll = new lcps.BLL.projectinfo();
            bll.Add(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "add.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }

        private void BindDDL()
        {
            //增加数据 日期的处理
            lcps.BLL.tableinfo bt = new BLL.tableinfo();
            ddltables.DataSource = bt.GetAllList().Tables[0];
            ddltables.DataTextField = "tablename";
            ddltables.DataValueField = "id";
            ddltables.DataBind();
        }
    }
}
